<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <style type="text/css">
			*{
				margin:0;
				padding:0;
				list-style:none;
			}
			.curr{
				background:#abcdef;
			}
        </style>
        <script type="text/javascript">
        	window.onload = function(){
        		var btns = document.getElementsByTagName("button");
        		//alert(btns.length)
        		for(var i=0; i<btns.length; i++){
        			btns[i].index = i
        			//alert(btns[i].index)
        			btns[i].onclick = function(){

        				for(var j=0; j<btns.length; j++){
        					btns[j].className = ""
        				}

        				this.className="curr"
        			}

        		}
        	} 
        </script>
    </head>
    <body>
    	<button>按钮</button>
    	<button>按钮</button>
    	<button>按钮</button>
    	<button>按钮</button>
    	<button>按钮</button>
    	<button>按钮</button>
    	<button>按钮</button>
    	<button>按钮</button>
    	<button>按钮</button>
    	<button>按钮</button>
    </body>
</html>